<template>
  <div>
    <el-dialog v-bind="dialogProps" :before-close="handleClose" :close-on-click-modal="false"
               :destroy-on-close="true" v-dialogDrag append-to-body>

      <el-form :model="ruleForm" ref="ruleForm" label-width="120px" class="demo-ruleForm" :size="size">
        <el-row :gutter="16" justify="start">

          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="设备名称:" prop="sbmc">
              <el-input v-model="ruleForm.sbmc" clearable placeholder="请输入设备名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="出厂编码:" prop="ccbm">
              <el-input v-model="ruleForm.ccbm" clearable placeholder="请输入出厂编码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item label="设备类型:" prop="sblxbm">
              <el-select v-model="ruleForm.sblxbm" placeholder="请选择设备状态" clearable style="width: 100%"
                         multiple disabled>
                <el-option v-for="item in OptionData_stockType" :key="item.value" :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
            <el-form-item style="float:right">
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <el-button style="margin-left: 10px" @click="handleReset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col :span="11" style="color:#000000">
          列表:
          <div style="height:2px;background:#009688;margin-bottom: 5px;"></div>
          <vxe-table border stripe height="500" :data="list1.data" @checkbox-all="selectAllEvent"
                     @checkbox-change="selectChangeEvent" ref="xTable" :loading="loading">
            <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
            <vxe-column type="checkbox" width="60" align="center"></vxe-column>
            <vxe-column field="sbmc" title="设备名称" align="center" minWidth="150"></vxe-column>
            <vxe-column field="ccbm" title="出厂编码" align="center" minWidth="150"></vxe-column>
            <vxe-column field="jlfsmc" title="计量方式" align="center" minWidth="150"></vxe-column>
            <vxe-column field="sbgg" title="规格" align="center" minWidth="150"></vxe-column>
            <vxe-column field="xh" title="型号" align="center" minWidth="150"></vxe-column>
            <vxe-column field="yxztmc" title="设备状态" align="center" minWidth="150"></vxe-column>
            <vxe-column field="ccrq" title="出厂时间" align="center" minWidth="150"></vxe-column>

          </vxe-table>
          <vxe-pager perfect size="mini" :current-page="list1.pageNo" :page-size="list1.pageSize"
                     :page-sizes="list1.pageSizes" :total="list1.total"
                     :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                     @page-change="handlePageChange1">
          </vxe-pager>
        </el-col>
        <el-col :span="2">
          <el-button style="position: absolute;top: 160px;right: 50%;transform:translateX(50%)" type="primary"
                     @click="handleSelect">选择
          </el-button>
          <el-button style="position: absolute;top: 211px;right: 50%;transform:translateX(50%)" type="primary"
                     @click="handleDelete">删除
          </el-button>
          <el-button style="position: absolute;top: 260px;right: 50%;transform:translateX(50%)" type="primary"
                     @click="handleClear">清空
          </el-button>
        </el-col>
        <el-col :span="11" style="color:#000000" :push="2">
          已选列表:
          <div style="height:2px;background:#009688;margin-bottom: 5px;"></div>
          <vxe-table border stripe height="500" :data="list2.data" @checkbox-all="selectAllEvent1"
                     @checkbox-change="selectChangeEvent1" ref="xTable1">
            <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
            <vxe-column type="checkbox" width="60" align="center"></vxe-column>
            <vxe-column field="sbmc" title="设备名称" align="center" minWidth="150"></vxe-column>
            <vxe-column field="ccbm" title="出厂编码" align="center" minWidth="150"></vxe-column>
            <vxe-column field="jlfsmc" title="计量方式" align="center" minWidth="150"></vxe-column>
            <vxe-column field="sbgg" title="规格" align="center" minWidth="150"></vxe-column>
            <vxe-column field="xh" title="型号" align="center" minWidth="150"></vxe-column>
            <vxe-column field="yxztmc" title="设备状态" align="center" minWidth="150"></vxe-column>
            <vxe-column field="ccrq" title="出厂时间" align="center" minWidth="150"></vxe-column>
          </vxe-table>
          <vxe-pager perfect size="mini" :current-page="list2.pageNo" :page-size="list2.pageSize"
                     :page-sizes="list2.pageSizes" :total="list2.total"
                     :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                     @page-change="handlePageChange2">
          </vxe-pager>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
                <el-button @click="handleCancel()" :size="size" icon="fa fa-minus-square-o">取消</el-button>
                <el-button type="primary" @click="handleSubmit()" :size="size"
                           icon="fa fa-save (alias)">确定</el-button>
            </span>
    </el-dialog>
  </div>
</template>
<script>
import {preparationTask} from '@/api/equip/preparationTask.js'

export default {
  props: {
    OptionData_stockType: {
      type: Array,
      default: () => []
    }

  },
  data() {
    return {
      size: "medium",
      ruleForm: {
        sbmc: '',//设备名称
        sblxbm: '',//设备类型
        ccbm: '',//出厂编码
        sskfbm: '001',

      },
      dialogProps: {
        visible: false,
        title: "选择设备",
        width: "80%",
        top: "10px",
      },
      list1: {
        data: [],
        pageNo: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100],
        total: 0
      },
      list2: {
        data: [],
        pageNo: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100],
        total: 0
      },
      loading: false,
      selectRow: null,
      selectRow1: null,
    };
  },
  methods: {
    showDialog(stockType) {
      this.ruleForm.sblxbm = stockType
      this.dialogProps.visible = true
      this.handleSearch()

    },

    //查询
    handleSearch() {
      let params = {
        column: "",
        entity: {
          sbmc: '*' + this.ruleForm.sbmc + '*',
          sblxbm: this.ruleForm.sblxbm.join(','),
          ccbm: '*' + this.ruleForm.ccbm + '*',
          sskfbm: '001',

        },
        order: "",
        pageNo: this.list1.pageNo,
        pageSize: this.list1.pageSize,
        paramsMap: {}
      }
      preparationTask.getEquipPage(params).then(res => {
        this.list1.data = res.data.records
        this.list1.total = res.data.total


      }).catch(err => {

      })


    },
    //重置
    handleReset() {
      this.ruleForm.sbmc = ''
      this.ruleForm.ccbm = ''
      this.handleSearch()

    },
    //分页查询
    handlePageChange1({currentPage, pageSize}) {
      this.loading = true
      this.list1.pageNo = currentPage;
      this.list1.pageSize = pageSize;
      this.handleSearch()
    },
    handlePageChange2({currentPage, pageSize}) {
      this.loading = true
      this.list2.pageNo = currentPage;
      this.list2.pageSize = pageSize;
    },
    //选择列表
    handleSelect() {
      const rows = this.$refs.xTable.getCheckboxRecords(true);
      console.log(rows)
      this.list2.data = rows

    },
    //删除已选
    handleDelete() {
      const rowArr = this.$refs.xTable1.getCheckboxRecords(true)
      this.list2.data = this.list2.data.filter(d => rowArr.findIndex(b => b.sbbm === d.sbbm) < 0)

    },
    //清空已选
    handleClear() {
      this.list2.data = []
      this.handleSearch()

    },

    selectAllEvent({checked}) {
      const records = this.$refs.xTable.getCheckboxRecords()
    },
    selectChangeEvent({checked}) {
      const records = this.$refs.xTable.getCheckboxRecords()
    },
    selectAllEvent1({checked}) {
      const records = this.$refs.xTable1.getCheckboxRecords()
    },
    selectChangeEvent1({checked}) {
      const records = this.$refs.xTable1.getCheckboxRecords()
    },
    //确定
    handleSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          if (this.list2.data.length === 0) {
            antd.message.warning('至少有一条数据')


          } else {
            this.$emit('onSelectEquips', this.list2.data,)
            this.dialogProps.visible = false;
            this.handleCancel()

          }

        } else {
          return false;
        }
      });

    },
    //取消
    handleCancel() {
      this.$refs.ruleForm.resetFields()
      this.dialogProps.visible = false;
      this.list2.data = []
    },
    handleClose(done) {

      this.handleCancel()
    },
  },
};
// 创建一个简单的超链接渲染
</script>
<style>
.el-dialog__footer {
  width: 100%;
  border-top: 1px solid #e8e8e8;
}
</style>
